import * as UE from 'ue'
import { $Nullable, $ref, $unref, $set, argv, on, toManualReleaseDelegate, releaseManualReleaseDelegate, blueprint } from 'puerts';

class GameServerContext {
    constructor(gameInstance: UE.AnimSampleGameInstance) {
        this.instance = gameInstance;
    }
    Tick(deltaTime: number): void {
        // console.log('GameServerContext Tick:', deltaTime);
    }

    instance: UE.AnimSampleGameInstance;
}

let InteractionFunction = {
    InteractionStart: function () {
        console.log("ServerInteractionStart")
    },
    InteractionStop: function () {
        console.log("ServerInteractionStop")
    },
    ParticipantStart: function () {
        console.log("ServerParticipantStart")
    },
    ParticipantStop: function () {
        console.log("ServerParticipantStop")
    }
};

function RegisterInteractionFunction(Object: UE.Object, DelegateName: string, FunctionName: string): void {
    Object[DelegateName].Bind(InteractionFunction[FunctionName]);
    console.log("RegisterInteractionFunction", "DelegateName", DelegateName, "FunctionName", FunctionName);
}

let gameInstance = (argv.getByName("GameInstance") as UE.AnimSampleGameInstance);
let gGameServerContext = new GameServerContext(gameInstance);

gameInstance.NotifyRegisterInteractionFunction.Bind(RegisterInteractionFunction);
gameInstance.NotifyRegisterSelfDefinedTickFunction.Bind(gGameServerContext.Tick);